/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.property.repository;

import me.zhengjie.modules.property.domain.Repay;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.Map;

/**
* @website https://el-admin.vip
* @author yyj
* @date 2023-04-21
**/
public interface RepayRepository extends JpaRepository<Repay, String>, JpaSpecificationExecutor<Repay> {


    @Query(value="select (select sum(repay_price) from repay where repay_status=\"0\") as no_repay_price,\n" +
            "(select sum(repay_principal) from repay where repay_status=\"0\") as no_repay_principal,\n" +
            "(select sum(repay_interest) from repay where repay_status=\"0\") as no_repay_interest,\n" +
            "(select sum(repay_price) from repay where repay_status=\"1\") as has_repay_price,\n" +
            "(select sum(repay_principal) from repay where repay_status=\"1\") as has_repay_principal,\n" +
            "(select sum(repay_interest) from repay where repay_status=\"1\") as has_repay_interest",nativeQuery=true)
    Map<String,Double> countTotalNum();

    @Query(value = "select sum(repay_price) from repay where repay_status='1'",nativeQuery = true)
    String hasRepay();

    @Query(value = "select sum(repay_principal) from repay where repay_status='0'",nativeQuery = true)
    String noRepay();

}